package com.sdp.right.db.sys_role.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdp.right.db.sys_role.mapper.SysRoleMapper;
import com.sdp.right.db.sys_role.service.ISysRoleService;
import com.sdp.right.entity.SysRole;
import com.sdp.right.utils.RightConstants;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsp
 * @since 2023-10-12
 */
@Service
@DS(value="right")
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

	@Override
	public List<SysRole> querySysRole(List<String> roleNos) {
		LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.in(SysRole::getRoleNo, roleNos);
		return list(queryWrapper);
	}

	@Override
	public SysRole querySysRole(String roleNo) {
		LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysRole::getRoleNo, roleNo);
		return getOne(queryWrapper,false);
	}

	@Override
	public void removeSysRole(String roleNo) {
		LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysRole::getRoleNo, roleNo);
		remove(queryWrapper);
	}

	@Override
	public boolean isDeveloper(List<String> roleNos) {
		boolean isDeveloper = false;
		List<SysRole> roles = querySysRole(roleNos);
		for(SysRole r : roles) {
			if(RightConstants.角色类型_开发人员.getCode().equals(r.getRoleType())) {
				isDeveloper = true;
				break;
			}
		}
		return isDeveloper;
	}

}
